<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<title></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp" %>
<!--[if lt IE 9]>
    <script src="lib/js/html5shiv.min.js"></script>
    <script src="lib/js/respond.min.js"></script>
<![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>已申报药品</h1>
        <ol class="breadcrumb">
             <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active"><a href="#">采购计划管理</a></li>
            <li class="active"><a href="#">申报采购计划</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
            	<div class="input">
            		<div class="textalign1">药品编码:</div>
            		<div class="boxinput">
            			<input class="textinput" type="text" id="drugCode" name="drugCode" placeholder="药品编码" />
            		</div>
            		<div class="textalign1">通用名:</div>
            		<div class="boxinput">
            			<input class="textinput" type="text" id="drugName" name="drugName" placeholder="通用名" />
            		</div>
            		<div class="textalign1">生产企业:</div>
            		<div class="boxinput">
            			<input class="textinput"  type="text" id="prodPompId" name="prodPompId" placeholder="生产企业" />
            		</div>
            		<div class="textalign1">
            			<button type="button" onclick="gridSerch()" class="btn btn-success btn-sm" id="selectc">查询</button>
            		</div>
            	</div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
		    <a href="javascript:void(0)" onclick="batchChangeStatus()" class="btn btn-default btn-sm">删&nbsp;除</a>
            <a href="${ctx }/bidHospplan/toDrugList.html?projId=${projId}&hospId=${hospId}" class="btn btn-default btn-sm">查看未申报药品</a>
            <a href="${ctx }/bidHospplan/toList.html" class="btn btn-default btn-sm">返&nbsp;回</a>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    //绑定回车
    $('#drugCode,#drugName,#prodPompId').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectc').click();
        }
    }); 
		
    $("#drugCode").focus();//加载页面光标在第一个查询框内

        $(function () {
            $("#gridlist").jqGrid({
                url: "${pageContext.request.contextPath}/bidHospplan/gotDrugDataList.html?projId=${projId}&hospId=${hospId}",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 255,
                colNames: ['proplanId','projId','hospId','drugid', '药品编码', '通用名', '剂型', '规格', '转换系数',"单位","材质", '生产企业', '去年采购数量','计划采购数量','采购方式','质量要求'],
                colModel: [
					{ name: 'projPlanId',hidden:true,key:true,width: 40, align: 'center' ,sortable: false},
                    { name: 'projId', hidden:true,width: 40, align: 'center' ,sortable: false},
                    { name: 'hospId',hidden:true, width: 80, align: 'center' ,sortable: false},
                    { name: 'drugId',hidden:true, width: 80, align: 'center' ,sortable: false},
                    { name: 'drugCode', width: 100, align: 'left' ,sortable: false,
                    	formatter: function (cellvalue,options,row){
                    		var str = "<a href=\"javascript:void(0)\" onclick=\"showDrugInfo('"+row.drugCode+"','"+row.drugName+"')\">"+cellvalue+"</a>";
							return str;
                    	}},
                    { name: 'drugName', width: 80, align: 'center' ,sortable: false},
                    { name: 'formName', width: 80, align: 'center' ,sortable: false},
                    { name: 'specName', width: 80, align: 'center' ,sortable: false},
                    { name: 'factor', width: 80, align: 'center' ,sortable: false},
                    { name: 'unit', width: 40, align: 'center' ,sortable: false},
                    { name: 'materialName', width: 60, align: 'center' ,sortable: false}, 
                    { name: 'prodPompName', width: 150, align: 'center' ,sortable: false,
                    	formatter:function(cellvalue, options, row){ 
							var str = "<a href=\"javascript:void(0)\" onclick=\"showCompInfo('"+row.compCode+"','"+row.prodPompName+"')\">"+cellvalue+"</a>";
							return str;
						}		
                    },
                    { name: 'lastyProAmt', width: 80, align: 'center' ,sortable: false},
                    { name: 'planProAmt', width: 80, align: 'center' ,sortable: false},
                    { name: 'proMethod', width: 80, align: 'center' ,sortable: false},
                    { name: 'qualityRequires', width: 80, align: 'center' ,sortable: false}
                    
                ],
                rowNum: 20,
                rowList: [10, 20,50,100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                multiselect: true,
                caption: "${projName}  -  申报采购计划",
                jsonReader: {
                	id:"projPlanId",
                    repeatitems: false  
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                },
                gridComplete: function(){
            		//序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
            	}
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        //查询
        function gridSerch() {
                  
        	var drugCode = $("#drugCode").val();
        	var drugName = $("#drugName").val();
        	var prodPompId = $("#prodPompId").val();
    		$("#gridlist").jqGrid('setGridParam',{
    	        datatype:'json',
    	        postData:{
    	        		"drugCode":drugCode,
    	        		"drugName":drugName,
    	        		"prodPompId":prodPompId
    	        		}
    	    }).trigger("reloadGrid"); //重新载入  
    	}
        

        
        
        
        //批量删除
        function batchChangeStatus() {
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请您选择要删除的药品！", "消息", "warn");
    			return;
    		}
    		var list = [];
    		var data = "";
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			var rowdata = $("#gridlist").jqGrid('getRowData', rowIds[i]);
    			list.push(rowdata.projPlanId);
    			data += "<br/>"+rowdata.drugName;
    		}
    		 $.HN.message.confirm("您确定删除以下药品吗？"+data, '', '').on(function (e) {
                 if (e) {
		    		$.post("${pageContext.request.contextPath}/bidHospplan/deleteData.html", {
		    			"array" : JSON.stringify(list)
		    		}, function(result) {
		    			if (result.success) {
		    				$.HN.message.alert("为您成功删除"+result.operCount+"条药品！", "消息", "success");
		    				gridSerch();
		    			} else {
		    				$.HN.message.alert("删除失败！", "消息", "error");
		    				gridSerch();
		    			}
		    		}, "json");
                 }
	          });
    	}
        
    </script>
</body>
</html>
